import AntModal from "@/components/pt/dialog/AntModal";
import {
  getBizYushenInfo,
  addBizYushenInfo,
  updateBizYushenInfo,
} from "@/api/biz/bizYushenInfo";

export default {
  name: "CreateForm",
  props: {},
  components: {
    AntModal,
  },
  data() {
    return {
      open: false,
      spinning: false,
      delayTime: 100,
      labelCol: { span: 4 },
      wrapperCol: { span: 14 },
      loading: false,
      total: 0,
      id: undefined,
      formTitle: "添加客户预审",
      // 表单参数
      form: {},
      rules: {},
    };
  },
  filters: {},
  created() {},
  computed: {},
  watch: {},
  mounted() {},
  methods: {
    onClose() {
      this.open = false;
      this.reset();
      this.$emit("close");
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
      this.$emit("close");
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        userId: undefined,

        deptId: undefined,

        userName: undefined,

        deptName: undefined,

        companyId: undefined,

        customerId: undefined,

        cusName: undefined,

        phone: undefined,

        amount: undefined,

        sort: undefined,

        status: undefined,
      };
    },
    /** 新增按钮操作 */
    handleAdd(item) {
      this.reset();
      this.open = true;
      /** 获取最大编号 */
      this.form.cusName = item.cusName;
      this.form.phone = item.phone;
      this.form.remark = "此额度为预审批额度，终审额度以银行审核为准";
      this.formTitle = "客户预审";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.open = true;
      this.spinning = !this.spinning;
      const bizYushenInfoId = row.id;
      getBizYushenInfo(bizYushenInfoId).then((response) => {
        this.form = response.data;
        this.formTitle = "修改客户预审";
        this.spinning = !this.spinning;
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs.form.validate((valid) => {
        if (valid) {
          const saveForm = JSON.parse(JSON.stringify(this.form));
          if (this.form.id !== undefined) {
            updateBizYushenInfo(saveForm).then((response) => {
              this.$message.success("修改成功", 3);
              this.open = false;
              this.$emit("ok");
              this.$emit("close");
            });
          } else {
            addBizYushenInfo(saveForm).then((response) => {
              // this.$message.success("新增成功", 3);
              this.open = false;
              this.$emit("ok", response.data);
              // this.$emit("close");
            });
          }
        } else {
          return false;
        }
      });
    },
    back() {
      const index = "/biz/yusheninfo/index";
      this.$router.push(index);
    },
  },
};
